package com.goodwilldd.myapp.services;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.goodwilldd.myapp.entities.Person;
import com.goodwilldd.myapp.repository.PersonRepository2;
import com.goodwilldd.myapp.services.impl.RepositoryPersonService2;
import com.mysema.query.types.Predicate;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class RepositoryPersonServiceTest2 {
	private static final String SEARCH_TERM = "foo";

	private RepositoryPersonService2 personService;

	private PersonRepository2 personRepositoryMock;

	@Before
	public void setUp() {
		personService = new RepositoryPersonService2();

		personRepositoryMock = mock(PersonRepository2.class);
		personService.setPersonRepository(personRepositoryMock);
	}

	@Test
	public void search() {
		List<Person> expected = new ArrayList<Person>();
		when(personRepositoryMock.findAll(any(Predicate.class))).thenReturn(
				expected);

		List<Person> actual = personService.search(SEARCH_TERM);

		verify(personRepositoryMock, times(1)).findAll(any(Predicate.class));
		verifyNoMoreInteractions(personRepositoryMock);

		assertEquals(expected, actual);
	}
}
